home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 11
/
CU Amiga Magazine's Super CD-ROM 11 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-06].iso
/
cucd
/
programming
/
oberonv4
/
source
/
system
/
remotetime.mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1996-07-15
|
3KB
|
95 lines
Syntax10.Scn.Fnt
MODULE RemoteTime;
(*BD, 13.2.96 *)
IMPORT SYSTEM, Texts, NetSystem, Oberon;
CONST timeoffset= 1;
VAR S: NetSystem.Socket;
ServerIP: NetSystem.IPAdr;
ServerName: ARRAY 64 OF CHAR;
W: Texts.Writer;
PROCEDURE ConvertTime(time: LONGINT; VAR aa, mm, dd, h, m, s: LONGINT);
VAR julian, d, f, dy: LONGREAL;
help, i, a, b, ce, g, mn, yr: LONGINT;
BEGIN
help:= SYSTEM.LSH(time, -7);
help:= help MOD 1FFFFFFH;
julian:= help / 675;
d:=julian+1; i:= ENTIER(d); f:= d - i;
IF ENTIER(f) = 1 THEN f:= 0; INC(i) END;
IF i > -115860 THEN
a:= ENTIER(((i/36524.25) + 0.99835726)) + 14;
i:= i +1+a-ENTIER(a/4);
END;
b:=ENTIER(((i/365.25) + 0.802601));
ce:= i-ENTIER((365.25*b)+0.750001) + 416;
g:= ENTIER(ce / 30.6001);
mn:= g-1;
dy:= ce - ENTIER((30.6001*g)) + f;
IF g>13.5 THEN mn:= g -13 END;
IF mn < 2.5 THEN yr:= b + 1900 ELSE yr:= b + 1899 END;
IF yr<1 THEN yr:= yr - 1 END;
aa:= yr;
mm:= mn;
dd:= ENTIER(dy);
help:= SYSTEM.LSH(time, -1);
help:= ((help MOD 43200) * 2) + time MOD 2;
h:= (help DIV 3600) + timeoffset; help:= help MOD 3600;
m:= help DIV 60; help:= help MOD 60;
s:= help;
END ConvertTime;
PROCEDURE WI(i: LONGINT);
BEGIN
IF i < 10 THEN Texts.WriteInt(W, 0, 1) END;
Texts.WriteInt(W, i, 1);
END WI;
PROCEDURE GetTime*;
VAR time, len: LONGINT;
timeDG, emptyDG: ARRAY 4 OF SYSTEM.BYTE;
res, port: INTEGER;
remIP: NetSystem.IPAdr;
TimeString: ARRAY 64 OF CHAR;
TimeStringAdr, i: LONGINT;
aa, mm, dd, h, m, s: LONGINT;
BEGIN
NetSystem.OpenSocket(S, 20968, res);
IF res = NetSystem.done THEN
emptyDG[0]:= 0X;
NetSystem.SendDG(S, ServerIP, 37, 0, 1, emptyDG);
len:= SIZE(LONGINT);
WHILE NetSystem.AvailableDG(S) = 0 DO END;
NetSystem.ReceiveDG(S, remIP, port, 0, len, timeDG);
NetSystem.GetLInt(timeDG, 0, time);
NetSystem.CloseSocket(S);
ConvertTime(time, aa, mm, dd, h, m, s);
END;
Texts.WriteString(W, "Current time on ");
Texts.WriteString(W, ServerName);
Texts.WriteString(W, " is: ");
WI(dd); Texts.WriteString(W, " . ");
WI(mm); Texts.WriteString(W, " . ");
WI(aa); Texts.WriteString(W, " , ");
WI(h); Texts.WriteString(W, " : ");
WI(m); Texts.WriteString(W, " : ");
WI(s); Texts.WriteLn(W);
Texts.Append(Oberon.Log, W.buf);
END GetTime;
PROCEDURE SetServer*;
VAR S: Texts.Scanner;
BEGIN
Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos);
Texts.Scan(S);
IF (S.class = Texts.Name) OR (S.class = Texts.String) THEN
COPY(S.s, ServerName);
NetSystem.GetIP(ServerName, ServerIP);
END
END SetServer;
BEGIN
Texts.OpenWriter(W);
NetSystem.Start;
COPY(NetSystem.hostname, ServerName);
NetSystem.GetIP(ServerName, ServerIP);
END RemoteTime.
RemoteTime.SetServer neptune~
RemoteTime.GetTime ~
System.Free RemoteTime ~